<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解JVM分层编译机制</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* Hero Section */
        .hero-section {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-pattern {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        /* Typography */
        .serif-title {
            font-family: 'Noto Serif SC', serif;
            letter-spacing: 0.05em;
        }
        
        /* Cards */
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.8);
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        /* Section Headers */
        .section-header {
            position: relative;
            padding-left: 1.5rem;
        }
        
        .section-header::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 80%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        /* Tier Cards */
        .tier-card {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            border: 2px solid transparent;
            background-clip: padding-box;
            position: relative;
            transition: all 0.3s ease;
        }
        
        .tier-card::before {
            content: '';
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            z-index: -1;
            margin: -2px;
            border-radius: inherit;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .tier-card:hover {
            transform: scale(1.02);
            box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
        }
        
        /* Mermaid Diagram Container */
        .mermaid-container {
            background: white;
            border-radius: 12px;
            padding: 2rem;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        /* First Letter Drop Cap */
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* Code Blocks */
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            padding: 1rem;
            border-radius: 8px;
            font-family: 'Consolas', 'Monaco', monospace;
            overflow-x: auto;
        }
        
        /* Smooth Scroll */
        html {
            scroll-behavior: smooth;
        }
        
        /* Navigation */
        .nav-item {
            transition: all 0.3s ease;
            position: relative;
        }
        
        .nav-item::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 2px;
            background: #667eea;
            transition: width 0.3s ease;
        }
        
        .nav-item:hover::after {
            width: 100%;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-section relative py-24 px-8">
        <div class="hero-pattern"></div>
        <div class="max-w-6xl mx-auto relative z-10">
            <div class="text-center text-white">
                <h1 class="serif-title text-5xl md:text-7xl font-bold mb-6 leading-tight">
                    深入理解JVM<br>分层编译机制
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90 max-w-3xl mx-auto">
                    探索Java虚拟机如何通过智能的编译策略，在启动速度与运行性能之间达到完美平衡
                </p>
                <div class="flex justify-center space-x-6 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-layer-group mr-2"></i>
                        <span>多层次优化</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-rocket mr-2"></i>
                        <span>动态编译</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-chart-line mr-2"></i>
                        <span>性能提升</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Navigation -->
    <nav class="sticky top-0 bg-white shadow-md z-50">
        <div class="max-w-6xl mx-auto px-8 py-4">
            <div class="flex justify-center space-x-8 text-gray-700">
                <a href="#overview" class="nav-item hover:text-purple-600">概述</a>
                <a href="#levels" class="nav-item hover:text-purple-600">编译层级</a>
                <a href="#mechanism" class="nav-item hover:text-purple-600">切换机制</a>
                <a href="#performance" class="nav-item hover:text-purple-600">性能权衡</a>
                <a href="#tuning" class="nav-item hover:text-purple-600">调优策略</a>
                <a href="#comparison" class="nav-item hover:text-purple-600">AOT对比</a>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-8 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="content-card rounded-2xl p-8 shadow-xl">
                <p class="text-lg leading-relaxed text-gray-700 drop-cap">
                    如果你曾经研究过 Java 的执行流程，可能会听说过即时编译器（JIT）的存在，JIT 编译器在运行时将字节码转换为机器码，从而加快程序的执行速度。但仅仅有一个编译器还不够，因为不同的方法在不同的执行场景中有着不同的优化需求。为了解决这个问题，JVM 引入了分层编译机制，它将编译任务交给不同层次的编译器来处理，达到在不同性能场景下的最佳平衡。
                </p>
                <div class="mt-8 grid grid-cols-1 md:grid-cols-3 gap-6">
                    <div class="text-center p-6 bg-purple-50 rounded-xl">
                        <i class="fas fa-tachometer-alt text-4xl text-purple-600 mb-4"></i>
                        <h3 class="font-bold text-lg mb-2">快速启动</h3>
                        <p class="text-gray-600">通过解释执行快速启动应用</p>
                    </div>
                    <div class="text-center p-6 bg-purple-50 rounded-xl">
                        <i class="fas fa-fire text-4xl text-purple-600 mb-4"></i>
                        <h3 class="font-bold text-lg mb-2">热点优化</h3>
                        <p class="text-gray-600">动态识别并优化热点代码</p>
                    </div>
                    <div class="text-center p-6 bg-purple-50 rounded-xl">
                        <i class="fas fa-balance-scale text-4xl text-purple-600 mb-4"></i>
                        <h3 class="font-bold text-lg mb-2">智能平衡</h3>
                        <p class="text-gray-600">在编译开销与性能间取得平衡</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Overview Section -->
        <section id="overview" class="mb-16">
            <h2 class="section-header serif-title text-4xl font-bold mb-8 text-gray-800">分层编译概述</h2>
            <div class="content-card rounded-2xl p-8 shadow-xl">
                <p class="text-lg leading-relaxed text-gray-700 mb-6">
                    <strong>分层编译（Tiered Compilation）</strong> 是JVM的一项关键优化机制，旨在平衡编译时间与运行时性能。它通过多阶段的编译策略，结合解释执行和不同级别的即时编译（JIT），使得JVM能够以渐进方式对代码进行优化，最大化性能提升的同时最小化编译的开销。
                </p>
                
                <!-- Compilation Flow Diagram -->
                <div class="mermaid-container my-8">
                    <div class="mermaid">
                        graph LR
                            A[字节码] --> B[解释执行<br/>Tier 0]
                            B --> C{热点探测}
                            C -->|低频执行| B
                            C -->|中频执行| D[C1编译器<br/>Tier 1-3]
                            C -->|高频执行| E[C2编译器<br/>Tier 4]
                            D --> F[轻量优化<br/>机器码]
                            E --> G[深度优化<br/>机器码]
                            
                            style A fill:#f9f,stroke:#333,stroke-width:2px
                            style B fill:#bbf,stroke:#333,stroke-width:2px
                            style C fill:#fbf,stroke:#333,stroke-width:2px
                            style D fill:#bfb,stroke:#333,stroke-width:2px
                            style E fill:#ffb,stroke:#333,stroke-width:2px
                    </div>
                </div>

                <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mt-8">
                    <div>
                        <h3 class="text-2xl font-bold mb-4 text-gray-800">
                            <i class="fas fa-history text-purple-600 mr-2"></i>背景与发展
                        </h3>
                        <p class="text-gray-700 leading-relaxed">
                            在JVM的早期版本中，代码要么以解释执行模式运行，要么通过JIT编译成机器码。解释执行速度较慢，但编译开销小；而JIT编译生成的机器码性能高，但编译过程会占用较多的CPU资源。为解决这两者之间的权衡，Java 7引入了分层编译。
                        </p>
                    </div>
                    <div>
                        <h3 class="text-2xl font-bold mb-4 text-gray-800">
                            <i class="fas fa-cogs text-purple-600 mr-2"></i>核心原理
                        </h3>
                        <p class="text-gray-700 leading-relaxed">
                            分层编译的核心思想是：不对所有代码一开始就进行深度优化，而是根据代码的执行频率（即"热点"）来逐步升级编译等级。这种渐进优化的方式能够在不影响启动时间的前提下，逐渐提升热点代码的性能。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Compilation Levels Section -->
        <section id="levels" class="mb-16">
            <h2 class="section-header serif-title text-4xl font-bold mb-8 text-gray-800">分层编译的级别</h2>
            <div class="space